<?
require_once('ConverterBase.php');

class ObjectConverter extends ConverterBase {
	private $className,$convertEmpty= true;
	public function setConvertEmptyString($value) { $this->convertEmpty= $value ? true : false; return $this; }
	public function getConvertEmptyString() { return $this->convertEmpty; }

	public function setClass($className) {
		$this->className= $className;
		return $this;
	}
	protected function toDatatype($string) {
		try {
			if (!empty($string) || $this->getConvertEmptyString())
				return new $this->className($string);
			return null;
		}
		catch (Exception $e) {
			throw new ConverterException($this,'Convertion from "'.$string.'" to "'.$this->className.'" failed.');
		}
	}
	protected function toString($data) {
		return (string)$data;
	}
}
